/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * mongoDB查询逻辑运算条件
 *
 * @author hxloongs
 * @date 2025-02-13
 */
@AllArgsConstructor
@Getter
public enum IsfdMongoQueryLogicalOperatorEnum {
    AND("and", "且"),
    OR("or", "并");


    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        IsfdMongoQueryLogicalOperatorEnum isfdMongoQueryLogicalOperatorEnum = forValue(value);
        if (isfdMongoQueryLogicalOperatorEnum == null) {
            return null;
        }
        return isfdMongoQueryLogicalOperatorEnum.getDesc();
    }

    public static IsfdMongoQueryLogicalOperatorEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (IsfdMongoQueryLogicalOperatorEnum isfdMongoQueryLogicalOperatorEnum : IsfdMongoQueryLogicalOperatorEnum.values()) {
            if (isfdMongoQueryLogicalOperatorEnum.getValue().equals(value)) {
                return isfdMongoQueryLogicalOperatorEnum;
            }
        }
        return null;
    }

    public static IsfdMongoQueryLogicalOperatorEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (IsfdMongoQueryLogicalOperatorEnum isfdMongoQueryLogicalOperatorEnum : IsfdMongoQueryLogicalOperatorEnum.values()) {
            if (desc.equals(isfdMongoQueryLogicalOperatorEnum.getDesc())) {
                return isfdMongoQueryLogicalOperatorEnum;
            }
        }
        return null;
    }
}
